Add airport, navaid, city, and landmarks to gpspilot. Courtesy Paul Tomblin.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 6 Apr 2003 19:34:56 +0000 (19:34 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 6 Apr 2003 19:34:56 +0000 (19:34 +0000)
gpsbabel/gpspilot.c

index 14b46807915c3a3018da3d63ddc744d94eb89436..267fea2b6d91ea930dbd3ebe25ab6412716292b4 100644 (file)
 #include "coldsync/pdb.h"
 
 #define MYNAME "GPSPilot"
-#define MYTYPE 0x706f696e      /* poin */
+#define MYTYPE_POINTS 0x706f696e       /* poin */
+#define MYTYPE_AIRPORT 0x706f3030      /* po00 */
+#define MYTYPE_CITIES  0x706f3031      /* po01 */
+#define MYTYPE_LNDMRKS 0x706f3032      /* po02 */
+#define MYTYPE_NAVAIDS 0x706f3033      /* po03 */
 #define MYCREATOR 0x47704c69   /* GpLi */
 
 struct record {
@@ -34,6 +38,13 @@ struct record {
        pdb_16 magvar;          /* magnetic variation in degrees, neg = west */
 };
 
+struct runways {
+       pdb_32 be_longitude;    /* Big endian, long * 3.6e6 */
+       pdb_32 be_latitude;     /* similarly */
+       pdb_32 en_longitude;    /* Big endian, long * 3.6e6 */
+       pdb_32 en_latitude;     /* similarly */
+};
+
 static FILE *file_in;
 static FILE *file_out;
 static const char *out_fname;
@@ -97,7 +108,19 @@ data_read(void)
                fatal(MYNAME ": pdb_Read failed\n");
        }
 
-       if ((pdb->creator != MYCREATOR) || (pdb->type != MYTYPE)) {
+       if ((pdb->creator != MYCREATOR)) {
+               fatal(MYNAME ": Not a gpspilot file.\n");
+       }
+
+       switch (pdb->type)
+       {
+       case MYTYPE_AIRPORT:
+       case MYTYPE_POINTS:
+       case MYTYPE_CITIES:
+       case MYTYPE_LNDMRKS:
+       case MYTYPE_NAVAIDS:
+         break;
+       default:
                fatal(MYNAME ": Not a gpspilot file.\n");
        }
 
@@ -110,10 +133,22 @@ data_read(void)
                rec = (struct record *) pdb_rec->data;
                wpt_tmp->position.longitude.degrees = be_read32(&rec->longitude) / 3.6e6; 
                wpt_tmp->position.latitude.degrees = be_read32(&rec->latitude) / 3.6e6; 
-               wpt_tmp->position.altitude.altitude_meters = be_read16(&rec->elevation) / 100.0;
+               wpt_tmp->position.altitude.altitude_meters =
+                 be_read16(&rec->elevation);
        
                vdata = (char *) pdb_rec->data + sizeof(*rec);
 
+               /*
+               * skip runway records if an airport.
+               */
+               if (pdb_rec->category == 0)
+               {
+                 int numRunways;
+                 numRunways = be_read16(vdata);
+                 vdata += 2;
+                 vdata += (sizeof(struct runways) * numRunways);
+               }
+
                /*
                 * This maping is a bit contrived.   
                 * Name is up to 36. ID is up to 9.
@@ -208,7 +243,7 @@ data_write(void)
        opdb->name[PDB_DBNAMELEN-1] = 0;
        opdb->attributes = PDB_ATTR_BACKUP;
        opdb->ctime = opdb->mtime = time(NULL) + 2082844800U;
-       opdb->type = MYTYPE;
+       opdb->type = MYTYPE_POINTS;
        opdb->creator = MYCREATOR; 
        opdb->version = 0;